package com.cit.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 
 * @author Lang Yu(lang.yu@hp.com)
 * @time Mar 7, 2011 11:34:17 AM
 * @file SoapFilter.java
 * @package com.cit.filter
 * @version 1.0
 * @see
 * This filter is used for reject the request which contains empty data, if the client send our web application
 * some request with no data or empty data, we'll reject the request. In this situation, the request content attribute's
 * may be as below:
 * ContentLength: -1
 * We must accept the standard soap messages, although the soap messages body part can be empty, but the http request
 * must contains some data, also the ContentLength must be greater than 0, so if we received the request data which
 * content length is less or equal to 0, the request is invalid.
 */
public class SoapFilter implements Filter {

	/**
	 * @see empty function with default action to release some resources in our web application
	 */
	public void destroy() {}

	/**
	 * @see main business process
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		/**
		 * Check the request content length
		 */
		if(request.getContentLength() <= 0){
			return;
		}
		/**
		 * Pass the filter, request data is valid.
		 */
		chain.doFilter(request, response);
	}

	/**
	 * @see empty function with default action to initialize the filter, sometimes we should read some configuration information
	 * here, but in our application, there is no need to write some code in this function
	 */
	public void init(FilterConfig fConfig) throws ServletException {

	}

}
